#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	FILE *Connection_data;
	FILE *NodeInfo;
	char NodeValue[8];
	char Command[1024];
	char login[64];
	char password[64];
	char server_name[64];
	char server_folder[512];

	if ((Connection_data = fopen( "connect.dat", "r+t" )) != NULL)	{
	  fscanf(Connection_data, "%s", login);
	  fscanf(Connection_data, "%s", password);
	  fscanf(Connection_data, "%s", server_folder);
      printf( "login = %s\n", password);
      fclose(Connection_data);
	}
	else
      printf( "File with server connection data could not be opened\n" );

	strcpy(login, "dsagent");
	strcpy(password, "free12pas");
	strcpy(server_name, "k100.kiam.ru");
	strcpy(server_folder, "visu_server/");
	sprintf(Command, "plink %s@%s -pw %s cat %shostname.dat > node.dat",
		login, server_name, password, server_folder);
	printf("%s\n", Command);
	system("dir");
	system(Command);
	if ((NodeInfo = fopen( "node.dat", "r+t" )) != NULL)	{
	  fscanf(NodeInfo, "%s", NodeValue);
      printf( "Contents of buffer = %s\n", NodeValue);
      fclose(NodeInfo);
	}
	else
      printf( "File could not be opened\n" );

	sprintf(Command, "plink %s@%s -pw %s -L 127.0.0.1:1701:%s:1701 -N",
		login, server_name, password, NodeValue);
	system(Command);

	return 0;
}